package com.qing.design.patterns.memento.example;

import java.time.LocalDateTime;

public class Demo {

	public static void main(String[] args) {
		Admin admin=new Admin();

		ConfigOriginator configOriginator=new ConfigOriginator();
		configOriginator.setConfigFile(new ConfigFile("1.0.1","这是第1个版本", LocalDateTime.now(),"AAA"));
		admin.append(configOriginator.saveMemento());//备份


		configOriginator.setConfigFile(new ConfigFile("1.0.2","这是第2个版本", LocalDateTime.now(),"BBB"));
		admin.append(configOriginator.saveMemento());//备份

		configOriginator.setConfigFile(new ConfigFile("1.0.3","这是第3个版本", LocalDateTime.now(),"DDD"));
		admin.append(configOriginator.saveMemento());//备份

		System.out.println("获取当前版本信息:"+configOriginator.getConfigFile().toString());
		//回滚
		configOriginator.getMemento(admin.undo());
		System.out.println("获取上一个版本："+configOriginator.getConfigFile().toString());
		// 回滚
		configOriginator.getMemento(admin.undo());
		System.out.println("获取上一个版本："+configOriginator.getConfigFile().toString());
		System.out.println("获取当前版本信息:"+configOriginator.getConfigFile().toString());

		//前进
		configOriginator.getMemento(admin.redo());
		System.out.println("前进一个版本："+configOriginator.getConfigFile().toString());

		configOriginator.setConfigFile(new ConfigFile("1.0.4","这是第4个版本", LocalDateTime.now(),"eee"));
		admin.append(configOriginator.saveMemento());//备份

		configOriginator.setConfigFile(new ConfigFile("1.0.5","这是第5个版本", LocalDateTime.now(),"fff"));
		admin.append(configOriginator.saveMemento());//备份

		System.out.println("获取当前版本信息:"+configOriginator.getConfigFile().toString());

		configOriginator.getMemento(admin.get("1.0.3"));
		System.out.println("获取1.0.3版本信息:"+configOriginator.getConfigFile().toString());
	}
}
